package io.renren.modules.app.service.impl;

import com.zheok.testing.entity.ActivityEntity;
import com.zheok.testing.entity.ShopEntity;
import io.renren.common.utils.ShiroUtils;
import io.renren.modules.app.service.BannerService;
import io.renren.modules.app.service.ShopService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.zheok.testing.dao.BannerDao;
import com.zheok.testing.entity.BannerEntity;



@Service("bannerService")
public class BannerServiceImpl extends ServiceImpl<BannerDao, BannerEntity> implements BannerService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BannerEntity> wrapper = new QueryWrapper<>();
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        String username = userEntity.getUsername();
        if(!"admin".equals(username)){
            wrapper.lambda().eq(BannerEntity::getShopId,userEntity.getUserId());
        }
        IPage<BannerEntity> page = this.page(
                new Query<BannerEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Autowired
    ShopService shopService;
    @Override
    public void saveinfo(BannerEntity banner) {
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        banner.setShopId(userEntity.getUserId());
        banner.setShopName(userEntity.getName());

        this.saveOrUpdate(banner);
    }

}